package com.databinding.jetpacktesting.room

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase

/**
 * Created by harisucici on 2020/3/14
 * Class description:
 */
//抽象类
//修改单例模式 因为耗资源
@Database(entities = [WordEntity::class], version = 1, exportSchema = false)
abstract class WordDataBase : RoomDatabase() {
    abstract val wordDao: WordDao?
    companion object {
        var INSTANCE: WordDataBase? = null
        @JvmStatic
        @Synchronized
        fun getInstance(context: Context): WordDataBase? {
            if (INSTANCE == null) {
                INSTANCE = Room.databaseBuilder(context.applicationContext, WordDataBase::class.java, "word_db")
                        .build()
            }
            return INSTANCE
        }
    }
}